package com.example.sunmiv1.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.sunmiv1.R;
import com.example.sunmiv1.entity.ModifyRecordBean;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class ModifyRecordAdapter extends BaseAdapter {

    private List<ModifyRecordBean.DataBean.ListBean> list;
    private ViewHolder viewHolder;

    public ModifyRecordAdapter(List<ModifyRecordBean.DataBean.ListBean> list) {
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.modify_record_adapter, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        }else{
            viewHolder = (ViewHolder) convertView.getTag();
        }
        ModifyRecordBean.DataBean.ListBean bean = list.get(position);
        viewHolder.modifyRecordTime.setText(bean.getAdd_time());
        viewHolder.modifyRecordUser.setText(bean.getOperator_name());
        viewHolder.modifyRecordOldCode.setText(bean.getOld_main_serial_number());
        viewHolder.modifyRecordOldCode1.setText(bean.getOld_auxiliary_serial_number_one());
        viewHolder.modifyRecordOldCode2.setText(bean.getOld_auxiliary_serial_number_two());
        viewHolder.modifyRecordCode.setText(bean.getMain_serial_number());
        viewHolder.modifyRecordCode1.setText(bean.getAuxiliary_serial_number_one());
        viewHolder.modifyRecordCode2.setText(bean.getAuxiliary_serial_number_two());
        return convertView;
    }

    static
    class ViewHolder {
        @BindView(R.id.modifyRecord_time)
        TextView modifyRecordTime;
        @BindView(R.id.modifyRecord_user)
        TextView modifyRecordUser;
        @BindView(R.id.modifyRecord_oldCode)
        TextView modifyRecordOldCode;
        @BindView(R.id.modifyRecord_oldCode1)
        TextView modifyRecordOldCode1;
        @BindView(R.id.modifyRecord_oldCode2)
        TextView modifyRecordOldCode2;
        @BindView(R.id.modifyRecord_code)
        TextView modifyRecordCode;
        @BindView(R.id.modifyRecord_code1)
        TextView modifyRecordCode1;
        @BindView(R.id.modifyRecord_code2)
        TextView modifyRecordCode2;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
